import modelExtend from '../../../utils/modelExtend';
import HttpModel from '../../../models/http';
import { doPostParam } from '@/services/http';

let appPicsConfig = {
  namespace: 'appPicsConfig',
  state: {
    pageList: {
      list: [],
      pagination: {},
    },
    data: {},
  },
  effects: {
    *fetchPageData({ payload, callback }, { call, put }) {
      const response = yield call(doPostParam, payload);
      if (response.statusCode === '0') {
        yield put({ type: 'req', payload: { pageList: response.data } });
        if (callback) callback(response);
        return response;
      }
    },
    *initData({ payload, callback }, { call, put }) {
      yield put({
        type: 'req',
        payload: {
          pageList: {
            list: [],
            pagination: {},
          },
          data: {},
        },
      });
    },
  },
  reducers: {
    req(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },
  },
};
appPicsConfig = modelExtend(HttpModel, appPicsConfig);
export default appPicsConfig;
